<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

</body>
<script>
  //响应拦截器
  function response_use() {
    // return { token: '123' }
    return Promise.reject(new Error('失败了'))
  }
  // 请求,发axios并且调用响应拦截器
  // axios方法是返回Promise
  function request() {
    return new Promise((resolve, reject) => {
      //调用拦截器
      resolve(response_use())
    })
  }
  //api里面login方法,调用axios的请求
  let api_login = function () {
    return request({
      url: '/login'
    })
  }
  //vuex里面action,调用api
  let action_login = async function name() {
    try {
      let token = await api_login()
      console.log('登录成功,跳转页面', token)
    } catch (e) {
      console.log('登录失败')
    }
  }
  action_login()
</script>

</html>
